﻿using Newtonsoft.Json;
using System.Text.Json;

namespace PatternExtensionDemo
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello, World!");

            //Pattern pattern = new Pattern();
            //pattern.RecipeId = 1;
            //pattern.Kind = 1;
            //pattern.Ordinal = 1;
            //pattern.Dx = 10;
            //pattern.Dy = 20;
            //pattern.AddrOffsetX = 10;
            //pattern.AddrOffsetY = 20;
            //pattern.Reference = new ReferenceOptions()
            //{
            //    ScanSettings = new ScanSettings()
            //    {
            //        ScanWidth = 100,
            //        Brightness = 100,
            //    },

            //    AutoFocusParam = new AutoFocusParam()
            //    {
            //        Mode = AutoFocusMode.Once,
            //        DotAvg = 100,
            //    },
            //    Threshold = 100,
            //};
            //pattern.Addressing = new AddressingOptions()
            //{
            //    ScanSettings = new ScanSettings()
            //    {
            //        ScanWidth = 200,
            //        Brightness = 200,
            //    },

            //    AutoFocusParam = new AutoFocusParam()
            //    {
            //        Mode = AutoFocusMode.Once,
            //        DotAvg = 200,
            //    },

            //    PreDoseOptions = new PreDoseOptions()
            //    { 
            //        AccVoltage = 200,
            //    },
            //    Threshold = 200,
            //};


            //string json = JsonSerializer.Serialize(pattern);


            string oldJson = "{\r\n  \"Id\": 0,\r\n  \"Kind\": 1,\r\n  \"Ordinal\": 1,\r\n  \"Dx\": 10,\r\n  \"Dy\": 20,\r\n  \"AddrOffsetX\": 10,\r\n  \"AddrOffsetY\": 20,\r\n  \"Reference\": {\r\n    \"ScanSettings\": {\r\n      \"ScanWidth\": 100,\r\n      \"Brightness\": 100,\r\n      \"Constrast\": 0,\r\n      \"FOV\": 0,\r\n      \"Rotation\": 0,\r\n      \"DotAvg\": 0,\r\n      \"LineAvg\": 0,\r\n      \"FrameAvg\": 0,\r\n      \"WaitTime\": 0,\r\n      \"IsAbcEnabled\": false,\r\n      \"AbcMethod\": 0,\r\n      \"AbcLevel\": 0\r\n    },\r\n    \"AutoFocusParam\": {\r\n      \"Mode\": 2,\r\n      \"DotAvg\": 100,\r\n      \"LineAvg\": 0,\r\n      \"FrameAvg\": 0,\r\n      \"Dx\": 0,\r\n      \"Dy\": 0,\r\n      \"FOV\": 0,\r\n      \"WaitTime\": 0\r\n    },\r\n    \"PreDoseOptions\": {\r\n      \"IsEnabled\": false,\r\n      \"WaitTime\": 0,\r\n      \"FOV\": 0,\r\n      \"AccVoltage\": 0\r\n    },\r\n    \"DoCentering\": false,\r\n    \"Threshold\": 100,\r\n    \"ImagePath\": null\r\n  },\r\n  \"Addressing\": {\r\n    \"ScanSettings\": {\r\n      \"ScanWidth\": 200,\r\n      \"Brightness\": 200,\r\n      \"Constrast\": 0,\r\n      \"FOV\": 0,\r\n      \"Rotation\": 0,\r\n      \"DotAvg\": 0,\r\n      \"LineAvg\": 0,\r\n      \"FrameAvg\": 0,\r\n      \"WaitTime\": 0,\r\n      \"IsAbcEnabled\": false,\r\n      \"AbcMethod\": 0,\r\n      \"AbcLevel\": 0\r\n    },\r\n    \"AutoFocusParam\": {\r\n      \"Mode\": 2,\r\n      \"DotAvg\": 200,\r\n      \"LineAvg\": 0,\r\n      \"FrameAvg\": 0,\r\n      \"Dx\": 0,\r\n      \"Dy\": 0,\r\n      \"FOV\": 0,\r\n      \"WaitTime\": 0\r\n    },\r\n    \"PreDoseOptions\": {\r\n      \"IsEnabled\": false,\r\n      \"WaitTime\": 0,\r\n      \"FOV\": 0,\r\n      \"AccVoltage\": 200\r\n    },\r\n    \"Threshold\": 200,\r\n    \"ImagePath\": null\r\n  },\r\n  \"CDPoints\": [],\r\n  \"Names\": [],\r\n  \"UseAddressing\": false,\r\n  \"Coordinates\": null,\r\n  \"UseDifferentialDrive\": false,\r\n  \"ParentId\": null,\r\n  \"RecipeId\": 1\r\n}";
            var pattern = JsonConvert.DeserializeObject<Pattern>(oldJson);

            // Threshold 已迁移到独立配置类
            //pattern.ThresholdConfig.Threshold == 100; // true

        }
    }
}
